﻿using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public static class PrintPathTool
{
    [MenuItem("Assets/[FutureCore]/Print/打印资源路径", false, -140)]
    private static void PrintAssetsPath()
    {
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);
        GUIUtility.systemCopyBuffer = path;
        DebugUtil.Log(path);
    }

    [MenuItem("Assets/[FutureCore]/Print/打印子项路径", false, -140)]
    private static void PrintItemAssetsPath()
    {
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);//Assets/_Game/Resources/Module/CommonUI/UpgradeCostItem.prefab
        path = path.Replace("Assets/_Game/Resources/Module/", "");
        path = path.Replace(".prefab", "");
        path = "\"" + path + "\"";
        GUIUtility.systemCopyBuffer = path;
        DebugUtil.Log(path);
    }

    [MenuItem("GameObject/[FutureCore]/打印对象路径", false, 0)]
    private static void OnSelectedChanged()
    {
        GameObject gobj = Selection.activeGameObject;
        List<Transform> list = new List<Transform>();
        if (gobj != null)
        {
            SetParentList(gobj, list);
            string path = string.Empty;
            for (int i = list.Count - 1; i >= 0; i--)
            {
                path += list[i].name + "/";
            }
            path += gobj.name;
            GUIUtility.systemCopyBuffer = path;
            DebugUtil.Log(path);
        }
    }

    private static void SetParentList(GameObject gobj, List<Transform> list)
    {
        if (gobj.transform.parent != null)
        {
            list.Add(gobj.transform.parent);
            SetParentList(gobj.transform.parent.gameObject, list);
        }
    }
}